package server

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"server/src/global"
	"server/src/middleware"
	router2 "server/src/router"
)

func InitRouters() *gin.Engine {
	router := gin.Default()
	router.StaticFS(global.GVL_CFG.Local.HeadUrl, http.Dir(global.GVL_CFG.Local.HeadUrl)) // 为用户头像和文件提供静态地址
	global.GVL_LOG.Info("use middleware logger")

	// 跨域
	router.Use(middleware.Cors()) // 如需跨域可以打开
	global.GVL_LOG.Info("use middleware cors")

	// 健康监测
	router.GET("/health", func(c *gin.Context) {
		c.JSON(200, "ok")
	})
	group := router.Group("/")
	{
		router2.CommonGroupUser.InitRouter(group)
	}

	adminUser := group.Group("/common")
	{
		router2.CommonRouter.InitRouter(adminUser)
		router2.CommonGuessRouter.InitRouter(adminUser)
	}

	robot := group.Group("/robot_admin")

	{
		router2.RobotAdminUserRouter.InitRouter(robot)
	}

	system := router.Group("system_admin")
	{
		router2.SystemAdminUserRouter.InitRouter(system)
	}
	//官网
	officail := group.Group("officail")
	{
		router2.OffGuess.InitRouter(officail)

	}
	return router
}
